package com.yyx.lgb.manager.controller;

import com.yyx.lgb.manager.service.CategoryService;
import com.yyx.lgb.model.entity.product.Category;
import com.yyx.lgb.model.vo.common.Result;
import com.yyx.lgb.model.vo.common.ResultCodeEnum;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * ClassName: CategoryController
 * Package: com.yyx.lgb.manager.controller
 * Description:
 *
 * @Author: yyx
 * @Create: 2025/8/6 - 10:09
 */
@RestController
@RequestMapping(value="/admin/product/category")
public class CategoryController {
        @Autowired
    private CategoryService categoryService;

        //分类列表查询 每次查一层数据（懒加载）
    @GetMapping("/findByParentId/{parentId}")
    public Result<List<Category>> findByParentId(@PathVariable Long parentId){
        List<Category> list=categoryService.findByParentId(parentId);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("exportData")
    public void exportData(HttpServletResponse response) {
        categoryService.exportData(response);
    }
    //导入
    @PostMapping("/importData")
    public Result importData(MultipartFile file) {
        categoryService.importData(file);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
}
